package jmg

import (
	"lol.com/feb214-game/nest.git/tools/tz"
	"talent.com/cube/common/cxt"
	"talent.com/cube/common/msg"
	"talent.com/cube/conf"
)

//龙虎主逻辑
type world struct {
	tc *cxt.TableContext
}

func NewTable(tc *cxt.TableContext) *world {
	winHistory := make(map[int32]*msg.JmgHistory)
	for diceIndex, _ := range HitIndexConf {
		winHistory[diceIndex] = &msg.JmgHistory{
			WinHistoryIndex: make([]int32, 0),
		}
	}
	tc.Jmt = &msg.JmgST{
		DiceIndex:  make(map[int32]int32),
		WinHistory: winHistory,
	}
	tc.Turn = 1
	return &world{
		tc: tc,
	}
}

// 结算
func (w *world) Settle() *msg.AwardNT {
	return announce(w)
}

func (w *world) NextTS() int64 {
	dxtConf := conf.JmgConfig().Game
	stopTS := w.tc.NextTS
	if stopTS == 0 {
		stopTS = tz.GetNowTsMs()
	}
	if w.tc.Stage == msg.TERM_STAGE_BET {
		//如果是第一轮，有额外的洗牌动画时间
		var shuffleTime int64
		if w.tc.Turn == 1 {
			shuffleTime = 1600
		}
		return dxtConf.BetTS*1000 + stopTS + shuffleTime
	} else {
		return dxtConf.AnnounceTS*1000 + stopTS
	}
}

func (w *world) CheckBetIndex(index int32) bool {
	return index >= allBetIndexes[0] && index <= allBetIndexes[len(allBetIndexes)-1]
}
